package glemipsc.implementations.glemips32;

import glemipsc.GLEMipsEmu;
import glemipsc.implementations.Argument;
import glemipsc.implementations.Instruction;

public class Lls extends Instruction {
	
	public Lls(Argument arg1, Argument arg2, Argument arg3) {
		arguments.add(arg1);
		arguments.add(arg2);
		arguments.add(arg3);
	}
	
	@Override
	public String getOpCode() {
		String opcode;
		
		// Register
		opcode = Instruction.ALU;
		opcode += arguments.get(1).getOpCode();
		opcode += zeros(5);
		opcode += arguments.get(0).getOpCode();
		opcode += arguments.get(2).getOpCode();
		opcode += Instruction.ALU_LLS;
		return opcode + "\n";
	}

	@Override
	public String getName() {
		return "LLS";
	}

	@Override
	public void emulate(GLEMipsEmu emu) {
		Register dest = (Register) arguments.get(0);
		Register op1 = (Register) arguments.get(1);
		if (arguments.get(2) instanceof Register)
			dest.setEmulValue(op1.getEmulValue() << ((Register) arguments.get(2)).getEmulValue());
		else
			dest.setEmulValue(op1.getEmulValue() << ((Immediate) arguments.get(2)).n);
	}

}
